<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>My Project: Src/M3508.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">My Project<span id="projectnumber">&#160;1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_413f4e031a85da0d68269c6fd2f76e1c.html">Src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle"><div class="title">M3508.c</div></div>
</div><!--header-->
<div class="contents">
<a href="_m3508_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="comment">/*</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="comment">*********************************************************************************************************</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="comment">*                                             INCLUDE FILES</span></div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="comment">*********************************************************************************************************</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span><span class="comment">*/</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="preprocessor">#include &quot;<a class="code" href="_m3508_8h.html">M3508.h</a>&quot;</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span> </div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="comment">/*</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span><span class="comment">*********************************************************************************************************</span></div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span><span class="comment">*                                               变量定义</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span><span class="comment">*********************************************************************************************************</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span><span class="comment">*/</span></div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"><a class="line" href="_m3508_8h.html#aaf6ff5f0e470c16dd7f23521b022e853">   25</a></span><a class="code hl_struct" href="struct_m3508___m_o_t_o_r.html">M3508_MOTOR</a> <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[9];</div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span><span class="comment">// 速度环PID</span></div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID1 = {7, 0.7, 0, 0, 0, 0, 0}; </div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID2 = {7, 0.7, 0, 0, 0, 0, 0}; </div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID3 = {7, 0.7, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID4 = {7, 0.7, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID5 = {7, 0.7, 0, 0, 0, 0, 0}; </div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID6 = {13, 0.72, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID7 = {7, 0.7, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508SpeedPID8 = {7, 0.7, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span> </div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span><span class="comment">// 位置环PID</span></div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID1 = {0.10, 0.10, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID2 = {0.10, 0.10, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID3 = {0.10, 0.10, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID4 = {0.10, 0.10, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID5 = {0.15, 0.05, 0.03, 0, 0, 0, 0};</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID6 = {0.2, 0.10, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID7 = {0.05, 0.04, 0.03, 0, 0, 0, 0};</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span><a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> M3508PositionPID8 = {0.10, 0.10, 0, 0, 0, 0, 0};</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span> </div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span> </div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span> </div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span><span class="keywordtype">void</span> M3508_Analyze(uint32_t M3508_StdId,uint8_t* MotorData)</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>{</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span> </div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>  <span class="keywordtype">char</span> Motor_Id;</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>  int16_t MotorVal[9][3];</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span> </div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>  Motor_Id = M3508_StdId - 0x200;</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span> </div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>  MotorVal[Motor_Id][0] = MotorData[0] &lt;&lt; 8 | MotorData[1]; <span class="comment">// 转子机械角度</span></div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>  MotorVal[Motor_Id][1] = MotorData[2] &lt;&lt; 8 | MotorData[3]; <span class="comment">// 转子转速</span></div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span> </div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>  MotorVal[Motor_Id][2] = MotorData[4] &lt;&lt; 8 | MotorData[5]; <span class="comment">// 转矩电流</span></div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span> </div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span>  <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel = MotorVal[Motor_Id][0] - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].CurPosition;</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span> </div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span>  <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].CurPosition == 0)</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno">   94</span>  {</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel = 0;</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>  }</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span> </div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>  <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel &gt;= 4095 &amp;&amp; <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].CurPosition != 0)</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>  {</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel = <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel - 8192;</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span>  }</div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span>  <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel &lt;= -4095 &amp;&amp; <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].CurPosition != 0)</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span>  {</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel = <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel + 8192;</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>  }</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span> </div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span>  <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].Temparg += <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].posdel;</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span>  <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].CurPosition = MotorVal[Motor_Id][0];</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>  <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].CurSpeed = MotorVal[Motor_Id][1];</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>  <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[Motor_Id].ActCurrent = MotorVal[Motor_Id][2];</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span>}</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span> </div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span><span class="keywordtype">void</span> M3508_Motor_Speed_Ctrl(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>{</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[1].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID1, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[1].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[1].CurSpeed);</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[2].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID2, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[2].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[2].CurSpeed);</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[3].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID3, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[3].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[3].CurSpeed);</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[4].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID4, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[4].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[4].CurSpeed);</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[5].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID5, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[5].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[5].CurSpeed);</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[6].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID6, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[6].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[6].CurSpeed);</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[7].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID7, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[7].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[7].CurSpeed);</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[8].OutCurrent += <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(&amp;M3508SpeedPID8, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[8].ExpSpeed - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[8].CurSpeed);</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span>}</div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span><span class="keywordtype">float</span> M3508_Motor_Signal_Position_Ctrl(<span class="keywordtype">int</span> M3508_id, <a class="code hl_struct" href="struct_p_i_d_type.html">PIDType</a> *M3508PositionPIDx)</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span>{</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span>  <span class="keywordtype">float</span> M3508ExpSpeed;</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span>  <span class="keywordflow">if</span> (abs(<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Exparg - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Temparg) &lt; 11000)</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno">  153</span>  {</div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno">  154</span>    M3508ExpSpeed = <a class="code hl_function" href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a>(M3508PositionPIDx, <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Exparg - <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Temparg);</div>
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno">  155</span>  }</div>
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno">  156</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Exparg &gt; <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Temparg)</div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno">  157</span>  {</div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno">  158</span>    M3508ExpSpeed = 1.05 * <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Expvel;</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno">  159</span>  }</div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno">  160</span>  <span class="keywordflow">else</span></div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno">  161</span>  {</div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno">  162</span>    M3508ExpSpeed = -1.05 * <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[M3508_id].Expvel;</div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno">  163</span>  }</div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno">  164</span>  <span class="keywordflow">return</span> M3508ExpSpeed;</div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno">  165</span>}</div>
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno">  178</span><span class="keywordtype">void</span> M3508_Motor_Position_Ctrl(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno">  179</span>{</div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno">  180</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[1].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(1, &amp;M3508PositionPID1);</div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno">  181</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[2].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(2, &amp;M3508PositionPID2);</div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno">  182</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[3].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(3, &amp;M3508PositionPID3);</div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno">  183</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[4].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(4, &amp;M3508PositionPID4);</div>
<div class="line"><a id="l00184" name="l00184"></a><span class="lineno">  184</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[5].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(5, &amp;M3508PositionPID5);</div>
<div class="line"><a id="l00185" name="l00185"></a><span class="lineno">  185</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[6].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(6, &amp;M3508PositionPID6);</div>
<div class="line"><a id="l00186" name="l00186"></a><span class="lineno">  186</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[7].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(7, &amp;M3508PositionPID7);</div>
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno">  187</span>    <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[8].ExpSpeed = (int16_t)M3508_Motor_Signal_Position_Ctrl(8, &amp;M3508PositionPID8);</div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno">  188</span>}</div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno">  189</span> </div>
<div class="line"><a id="l00212" name="l00212"></a><span class="lineno">  212</span><span class="keywordtype">void</span> M3508_Motor_Send_Current(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00213" name="l00213"></a><span class="lineno">  213</span>{</div>
<div class="line"><a id="l00214" name="l00214"></a><span class="lineno">  214</span>    uint8_t i;</div>
<div class="line"><a id="l00215" name="l00215"></a><span class="lineno">  215</span>    uint32_t send_mail_box;</div>
<div class="line"><a id="l00216" name="l00216"></a><span class="lineno">  216</span>    CAN_TxHeaderTypeDef TxHeader;</div>
<div class="line"><a id="l00217" name="l00217"></a><span class="lineno">  217</span>    TxHeader.StdId = 0x200;</div>
<div class="line"><a id="l00218" name="l00218"></a><span class="lineno">  218</span>    TxHeader.IDE = CAN_ID_STD;</div>
<div class="line"><a id="l00219" name="l00219"></a><span class="lineno">  219</span>    TxHeader.RTR = CAN_RTR_DATA;</div>
<div class="line"><a id="l00220" name="l00220"></a><span class="lineno">  220</span>    TxHeader.DLC = 0x08;</div>
<div class="line"><a id="l00221" name="l00221"></a><span class="lineno">  221</span>    TxHeader.TransmitGlobalTime = DISABLE;</div>
<div class="line"><a id="l00222" name="l00222"></a><span class="lineno">  222</span>    uint8_t Txmsg[8] = {0};</div>
<div class="line"><a id="l00223" name="l00223"></a><span class="lineno">  223</span> </div>
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno">  224</span>    <span class="keywordflow">for</span> (i = 1; i &lt;= 8; i++)</div>
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno">  225</span>    {</div>
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno">  226</span>        <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent &gt; 16384)</div>
<div class="line"><a id="l00227" name="l00227"></a><span class="lineno">  227</span>        {</div>
<div class="line"><a id="l00228" name="l00228"></a><span class="lineno">  228</span>            <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent = 16384;</div>
<div class="line"><a id="l00229" name="l00229"></a><span class="lineno">  229</span>        }</div>
<div class="line"><a id="l00230" name="l00230"></a><span class="lineno">  230</span>        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent &lt; -16384)</div>
<div class="line"><a id="l00231" name="l00231"></a><span class="lineno">  231</span>        {</div>
<div class="line"><a id="l00232" name="l00232"></a><span class="lineno">  232</span>            <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent = -16384;</div>
<div class="line"><a id="l00233" name="l00233"></a><span class="lineno">  233</span>        }</div>
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno">  234</span>    }</div>
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno">  235</span>    Txmsg[0] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[1].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno">  236</span>    Txmsg[1] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[1].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00237" name="l00237"></a><span class="lineno">  237</span>    Txmsg[2] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[2].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00238" name="l00238"></a><span class="lineno">  238</span>    Txmsg[3] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[2].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno">  239</span>    Txmsg[4] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[3].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno">  240</span>    Txmsg[5] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[3].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno">  241</span>    Txmsg[6] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[4].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00242" name="l00242"></a><span class="lineno">  242</span>    Txmsg[7] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[4].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00243" name="l00243"></a><span class="lineno">  243</span>    <span class="keywordflow">if</span>(HAL_CAN_AddTxMessage(&amp;hcan1, &amp;TxHeader, Txmsg, &amp;send_mail_box)!=HAL_OK)</div>
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno">  244</span>    {</div>
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno">  245</span>        Error_Handler();</div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno">  246</span>    }</div>
<div class="line"><a id="l00247" name="l00247"></a><span class="lineno">  247</span>}</div>
<div class="line"><a id="l00260" name="l00260"></a><span class="lineno">  260</span><span class="keywordtype">void</span> M3508_Motor_Current_Ctrl_h(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00261" name="l00261"></a><span class="lineno">  261</span>{</div>
<div class="line"><a id="l00262" name="l00262"></a><span class="lineno">  262</span>    uint8_t i;</div>
<div class="line"><a id="l00263" name="l00263"></a><span class="lineno">  263</span>    uint32_t send_mail_box;</div>
<div class="line"><a id="l00264" name="l00264"></a><span class="lineno">  264</span>    CAN_TxHeaderTypeDef TxHeader;</div>
<div class="line"><a id="l00265" name="l00265"></a><span class="lineno">  265</span>    TxHeader.StdId = 0x1FF;</div>
<div class="line"><a id="l00266" name="l00266"></a><span class="lineno">  266</span>    TxHeader.IDE = CAN_ID_STD;</div>
<div class="line"><a id="l00267" name="l00267"></a><span class="lineno">  267</span>    TxHeader.RTR = CAN_RTR_DATA;</div>
<div class="line"><a id="l00268" name="l00268"></a><span class="lineno">  268</span>    TxHeader.DLC = 0x08;</div>
<div class="line"><a id="l00269" name="l00269"></a><span class="lineno">  269</span>    TxHeader.TransmitGlobalTime = DISABLE;</div>
<div class="line"><a id="l00270" name="l00270"></a><span class="lineno">  270</span>    uint8_t Txmsg[8] = {0};</div>
<div class="line"><a id="l00271" name="l00271"></a><span class="lineno">  271</span> </div>
<div class="line"><a id="l00272" name="l00272"></a><span class="lineno">  272</span>    <span class="keywordflow">for</span> (i = 1; i &lt;= 8; i++)</div>
<div class="line"><a id="l00273" name="l00273"></a><span class="lineno">  273</span>    {</div>
<div class="line"><a id="l00274" name="l00274"></a><span class="lineno">  274</span>        <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent &gt; 16384)</div>
<div class="line"><a id="l00275" name="l00275"></a><span class="lineno">  275</span>        {</div>
<div class="line"><a id="l00276" name="l00276"></a><span class="lineno">  276</span>            <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent = 16384;</div>
<div class="line"><a id="l00277" name="l00277"></a><span class="lineno">  277</span>        }</div>
<div class="line"><a id="l00278" name="l00278"></a><span class="lineno">  278</span>        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent &lt; -16384)</div>
<div class="line"><a id="l00279" name="l00279"></a><span class="lineno">  279</span>        {</div>
<div class="line"><a id="l00280" name="l00280"></a><span class="lineno">  280</span>            <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[i].OutCurrent = -16384;</div>
<div class="line"><a id="l00281" name="l00281"></a><span class="lineno">  281</span>        }</div>
<div class="line"><a id="l00282" name="l00282"></a><span class="lineno">  282</span>    }</div>
<div class="line"><a id="l00283" name="l00283"></a><span class="lineno">  283</span>    Txmsg[0] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[5].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00284" name="l00284"></a><span class="lineno">  284</span>    Txmsg[1] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[5].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00285" name="l00285"></a><span class="lineno">  285</span>    Txmsg[2] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[6].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00286" name="l00286"></a><span class="lineno">  286</span>    Txmsg[3] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[6].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00287" name="l00287"></a><span class="lineno">  287</span>    Txmsg[4] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[7].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00288" name="l00288"></a><span class="lineno">  288</span>    Txmsg[5] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[7].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00289" name="l00289"></a><span class="lineno">  289</span>    Txmsg[6] = (uint8_t)((<a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[8].OutCurrent &gt;&gt; 8) &amp; 0xFF);</div>
<div class="line"><a id="l00290" name="l00290"></a><span class="lineno">  290</span>    Txmsg[7] = (uint8_t)( <a class="code hl_variable" href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a>[8].OutCurrent &amp; 0xFF);</div>
<div class="line"><a id="l00291" name="l00291"></a><span class="lineno">  291</span>    HAL_CAN_AddTxMessage(&amp;hcan1, &amp;TxHeader, Txmsg, &amp;send_mail_box);</div>
<div class="line"><a id="l00292" name="l00292"></a><span class="lineno">  292</span>}</div>
<div class="ttc" id="a_m3508_8c_html_aaf6ff5f0e470c16dd7f23521b022e853"><div class="ttname"><a href="_m3508_8c.html#aaf6ff5f0e470c16dd7f23521b022e853">M3508</a></div><div class="ttdeci">M3508_MOTOR M3508[9]</div><div class="ttdoc">M3508电机参数</div><div class="ttdef"><b>Definition</b> <a href="_m3508_8c_source.html#l00025">M3508.c:25</a></div></div>
<div class="ttc" id="a_m3508_8h_html"><div class="ttname"><a href="_m3508_8h.html">M3508.h</a></div></div>
<div class="ttc" id="a_p_i_d_8h_html_ae7af70aae342244ae4d41a8ffd1f288c"><div class="ttname"><a href="_p_i_d_8h.html#ae7af70aae342244ae4d41a8ffd1f288c">PIDCal</a></div><div class="ttdeci">float PIDCal(PIDType *PIDptr, float ThisError)</div><div class="ttdoc">增量式PID</div><div class="ttdef"><b>Definition</b> <a href="_p_i_d_8c_source.html#l00036">PID.c:36</a></div></div>
<div class="ttc" id="astruct_m3508___m_o_t_o_r_html"><div class="ttname"><a href="struct_m3508___m_o_t_o_r.html">M3508_MOTOR</a></div><div class="ttdoc">M3508电机参数</div><div class="ttdef"><b>Definition</b> <a href="_m3508_8h_source.html#l00031">M3508.h:32</a></div></div>
<div class="ttc" id="astruct_p_i_d_type_html"><div class="ttname"><a href="struct_p_i_d_type.html">PIDType</a></div><div class="ttdoc">PID参数结构体</div><div class="ttdef"><b>Definition</b> <a href="_p_i_d_8h_source.html#l00030">PID.h:31</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.7
</small></address>
</body>
</html>
